using UnityEngine;

public class BodyPartBurner : MonoBehaviour
{
	public float burningdamage;

	public float burningChance;

	public int burningLimit;

	public float resetAfterBurning;

	public float checkRadius;

	public Weapon weapon;

	public BodyPartFire fire;

	[Header("Runtime")]
	public int burningCount;

	public float resetTime;

	private void OnTriggerEnter2D(Collider2D collision)
	{
		if ((bool)CampaignGame.Instance.player && collision.gameObject.TryGetComponent<BodyPart>(out var component) && (!(checkRadius > 0f) || !(Mathf.Abs(component.body.zombie.transform.position.y - CampaignGame.Instance.player.transform.position.y) > checkRadius)))
		{
			if ((bool)weapon)
			{
				component.OnHit(weapon, Vector2.right, Vector2.zero);
			}
			if (resetTime <= Time.time)
			{
				burningCount = 0;
			}
			if (component.onFire == null && component.damageRatio >= 1f && burningLimit > burningCount && burningChance >= Random.Range(1f, 0f))
			{
				component.onFire = Object.Instantiate(fire, component.transform);
				component.onFire.damage = burningdamage;
				burningCount++;
				resetTime = Time.time + resetAfterBurning;
			}
		}
	}
}
